package com.whmnx.my.ui.viewmodel;


import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

import com.whmnx.base.bean.JiaoYiBean;
import com.whmnx.base.bean.LoginBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.my.BR;
import com.whmnx.my.R;
import com.whmnx.my.ui.fragment.FabuShouGouFragment;

import java.util.HashMap;
import java.util.Map;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 *
 * @author goldze
 * @date 2018/7/18
 */

public class ViewPagerItemInsideViewModel extends ItemViewModel<InsideModel> {
    public String text;
    private int index;

    //交易价格
    public ObservableField<String> textPrice = new ObservableField<>("");


    //用户名的绑定
    public ObservableField<String> textttt = new ObservableField<>("发布播豆收购");

    public ViewPagerItemInsideViewModel(@NonNull InsideModel viewModel, int index) {
        super(viewModel);
        this.index = index;
        if (index == 1){
            textttt.set("发布播豆收购");
        }else {
            textttt.set("发布播豆出售");
        }
        getDeallist(index);
    }

    private void getDeallist(int index) {
        Map<String, Object> params = new HashMap<>();
        params.put("deal_Type",index - 1);
        params.put("pageIndex",1);
        params.put("pageSize",20);
        params.put("sortOrder",true);
        HttpClient.post(viewModel.getApplication(), Constants.DEALLIST, params,new CallBack<JiaoYiBean>() {
            @Override
            public void onSuccess(JiaoYiBean result) {
                textPrice.set(result.getAveragePrice() + "");
                if (result.getRecordList().size() > 0){
                    for (JiaoYiBean.RecordListBean recordListBean : result.getRecordList()) {
                        observableList.add(new InsideItemViewModel(viewModel,recordListBean));
                    }
                }
            }
        });
    }

    //给RecyclerView添加ObservableList
    public ObservableList<InsideItemViewModel> observableList = new ObservableArrayList<>();
    //给RecyclerView添加ItemBinding
    public ItemBinding<InsideItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.grid_inside);


    //底部按钮 //发布收购
    public BindingCommand OnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putInt("index", index);
            viewModel.startContainerActivity(FabuShouGouFragment.class.getCanonicalName(), bundle);
        }
    });

    public BindingCommand OnClickCommand1 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

        }
    });

    public BindingCommand OnClickCommand2 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

        }
    });

    public BindingCommand OnClickCommand3 = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

        }
    });
}
